import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-07-01
 * Time：14:16
 */
public class RedisDemoSet {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()) {
            test6(jedis);
        }
    }

    private static void test6(Jedis jedis) {
        System.out.println("sinterstore");
        jedis.flushDB();

        jedis.sadd("key", "111", "222", "333", "444");
        jedis.sadd("key2", "333", "444", "555", "666");

        long len = jedis.sinterstore("key3", "key", "key2");
        System.out.println("len: " + len);

        System.out.println(jedis.smembers("key3"));
    }

    private static void test5(Jedis jedis) {
        System.out.println("sinter");
        jedis.flushDB();

        jedis.sadd("key", "111", "222", "333", "444");
        jedis.sadd("key2", "333", "444", "555", "666");

        Set<String> result = jedis.sinter("key", "key2");
        System.out.println(result);
    }

    private static void test4(Jedis jedis) {
        System.out.println("spop");
        jedis.flushDB();

        jedis.sadd("key", "111", "222", "333");
        System.out.println(jedis.spop("key"));
        System.out.println(jedis.spop("key"));
        System.out.println(jedis.spop("key"));
    }

    private static void test3(Jedis jedis) {
        System.out.println("scard");
        jedis.flushDB();

        jedis.sadd("key", "111", "222", "333");
        System.out.println(jedis.scard("key"));
    }

    private static void test2(Jedis jedis) {
        System.out.println("sismember");
        jedis.flushDB();

        jedis.sadd("key", "111", "222", "333");
        System.out.println(jedis.sismember("key", "111"));
        System.out.println(jedis.sismember("key", "555"));
    }

    private static void test1(Jedis jedis) {
        System.out.println("sadd/smembers");
        jedis.flushDB();

        jedis.sadd("key", "111", "222", "333");
        Set<String> result = jedis.smembers("key");
        System.out.println(result);
    }
}
